package com.chuang.bootplus.controller.news;


import com.chuang.bootplus.base.utils.ApiResponse;
import com.chuang.bootplus.po.HotnewsPO;
import com.chuang.bootplus.po.LovePO;
import com.chuang.bootplus.po.NewsAddPO;
import com.chuang.bootplus.service.HotnewsService;
import com.chuang.bootplus.service.LoveService;
import com.chuang.bootplus.vo.HotNewsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-10-24
 */
@RestController
@RequestMapping("/hotnews")
@Api(tags = {"新闻信息"})
@CrossOrigin(origins = "*")
public class HotnewsController {

    @Autowired
    HotnewsService hotnewsService;

    @Autowired
    LoveService loveService;

    @PostMapping("getnews")
    @ApiOperation(httpMethod = "POST", value = "获取新闻信息")
    public ApiResponse<HotNewsVO> getnews(@RequestBody HotnewsPO po){
        return hotnewsService.getnews(po);
    }


    @PostMapping("addnews")
    @ApiOperation(httpMethod = "POST", value = "添加新闻信息")
    @RequiresAuthentication
    public ApiResponse<Void> addnews(@RequestBody NewsAddPO po){
        return hotnewsService.addnews(po);
    }


    @PostMapping("getnewsById")
    @ApiOperation(httpMethod = "POST", value = "获取指定新闻信息")
    @RequiresAuthentication
    public ApiResponse<HotNewsVO> getnewsById(@RequestBody HotnewsPO po){
        return hotnewsService.getnewsById(po);
    }

    @PostMapping("love")
    @ApiOperation(httpMethod = "POST", value = "新闻点赞")
    public ApiResponse<Void> love(@RequestBody LovePO po){
        return hotnewsService.love(po);
    }
    @PostMapping("deletelove")
    @ApiOperation(httpMethod = "POST", value = "取消点赞")
    public ApiResponse<Void> deletelove(@RequestBody LovePO po){

        return hotnewsService.deletelove(po);
    }

    @PostMapping("gethotlove")
    @ApiOperation(httpMethod = "POST", value = "获取新闻热榜")
    public ApiResponse<HotNewsVO> gethostlove(){

        return hotnewsService.gethostlove();
    }








}

